home *** CD-ROM | disk | FTP | other *** search
- Path: news1.erols.com!newsmaster@erols.com
- From: ccobb <ccobb@erols.com>
- Newsgroups: comp.lang.c++
- Subject: extern consts
- Date: 16 Mar 1996 03:09:19 GMT
- Organization: CSEG, Inc.
- Message-ID: <4idbcv$ue2@news7.erols.com>
- NNTP-Posting-Host: ccobb.erols.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
-
- The following code works on one C++ compiler but does not work on two
- others I have tried. Can anyone give me an authoritive answer as to
- whether this is legal C++?
-
- --- xxx.h ---
- extern const int MYCONST;
- --- xxx.cc ---
- #include "xxx.h"
- const int MYCONST = 11;
- --- yyy.cc ---
- #include <iostream.h>
- #include "xxx.h"
- main()
- {
- char myarray[MYCONST];
-
- cout << "MYCONST is " << MYCONST << endl;
- cout << "sizeof myarray[] is " << sizeof(myarray) << endl;
- return 0;
- }
- --- end ---
-
- The whole point here is whether consts can be extern. Arrays require
- constant expressions. Techincally, the array size is a constant because
- it is declared const. However, the value of the constant is set in
- another file. This means that you could change your constants without
- having to recompile! If you think the above is trivial you are missing
- the point. The above is not possible in C nor in two of the three C++
- compilers I have tried it on.
-
- Any comments?
-
- Chris Cobb
- ccobb@erols.com
-
-